const app = getApp()
import api from "../../utils/util"
import cache from "../../utils/cache"
const db = wx.cloud.database()
Page({
  data() {
    return {
      dd: 'xxx',
      ss: 'sss' + this.dd,
      newsList: [{
        "title": "声明",
        "content": ""
      }],
      time: ["08:30", "10:25", "14:00", "15:45", "19:00"],
      titleList: ["hi，早上好！😊", "永远相信美好的事情即将发生", "生活再平凡，也是限量版🙌", "我随手一打就是十个字", "有趣都藏在无聊的日子里😉", "逆风的方向，更适合飞行", "生活晴朗，万物可爱😁", "但行好事，莫问前程", "去更远的地方，见更亮的光👍"],

      //开学周期 week周 day星期
      Today: {
        week: '',
        //今日时间（2020/4/11 星期六）
        theDay: '',
        day: ''
      },
      //学号
      xh: '233',
      //今日课程
      course: "",
      DataList: "",
      help: true
    }
  },


  onLoad: function () {
    const that = this
    this.getNotice();
    const xh = cache.getStuID();
    const help = cache.getHelp();
    const theDay = api.getTheday()
    const week = api.getWeek()


    this.setData({
      xh,
      help,
      Today: {
        week: week,
        theDay: theDay
      }
    })
    api.getC({
      success(res) {
        console.log('html' + res)
        that.setData({
          DataList: res
        })
        that.curr(that)
      }
    });

  },
  // 下拉刷新事件
  onPullDownRefresh: function () {
    qq.reLaunch({
      url: 'index'
    });
  },
  // 分享事件
  onShareAppMessage: function () {
    return {
      title: '我正在使用',
      desc: '「工程课表」,提供工程学院在校师生课表等查询服务。',
      path: '/pages/index/index'
    };
  },
  filed: function (res) {
    console.log(res)
  },
  Tocour: function () {
    if (this.data.xh.length < 9) {
      qq.showToast({
        icon: 'none',
        title: '请设置正确的学号'
      })
      qq.redirectTo({
        url: '../core/set/today'
      });
    } else {
      qq.switchTab({
        url: '/pages/core/table/index'
      });
    }
  },
  getNotice: function () {
    // 查询当前用户所有的 counters
    db.collection('Notice').orderBy("Grade", "asc").get({
      success: res => {
        console.log(res)
        this.setData({
          newsList: res.data
        })
      },
      fail: err => {
        qq.showToast({
          icon: 'none',
          title: '查询Notice记录失败'
        })
      }
    })
  },
  curr: function (mContext) {
    let result = mContext.data.DataList.filter(function (item) {
      return item.weekDay === mContext.data.Today.week.currday + ''
    });
    this.setData({
      course: result
    })
  },
  toHelp: function () {
    qq.setStorageSync('help', 'cc');
    qq.navigateTo({
      url: '../more/help'
    });
  },
  setxh: function () {
    qq.redirectTo({
      url: '../core/set/today'
    });
  }
})
